package com.zhilianbao.leyaogo.ui.adapter.shoppingcart;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bql.animationcheckbox.AnimationCheckBox;
import com.bql.baseadapter.recycleView.QuickRcvAdapter;
import com.bql.baseadapter.recycleView.QuickRcvHolder;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.model.response.address.Address;

import java.util.List;

/**
 * Author: hcy
 * Description:收货地址Adapter
 * Created: 2016/10/24 19:27
 */
public class ReceiveAddressAdapter extends QuickRcvAdapter<Address> {

    private long id;

    public ReceiveAddressAdapter(Context context, List<Address> data) {
        super(context, data, R.layout.item_receive_address);
    }

    public void setLastId(long id) {
        this.id = id;
    }

    @Override
    protected void bindDataHelper(QuickRcvHolder viewHolder, int position, Address item) {
        viewHolder.setText(R.id.tv_name,item.getAdName()).setText(R.id.tv_phone,item.getAdPhone())
                .setText(R.id.tv_address,item.getStrAddress());
        ImageView defaultIv = viewHolder.getView(R.id.iv_default);
        if (item.getIsDefault()==1) {
            defaultIv.setVisibility(View.VISIBLE);
        }else {
            defaultIv.setVisibility(View.GONE);
        }
        viewHolder.getView(R.id.ll_modify).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnModifyClickListener!=null){
                    mOnModifyClickListener.modify(position);
                }
            }
        });
        AnimationCheckBox checkBox = viewHolder.getView(R.id.anim_check_box);
        checkBox.setTag(position);
        if (id==item.getAddressId()) {
            checkBox.setChecked(true,false);
        }else {
            checkBox.setChecked(false,false);
        }
        checkBox.setOnClickListener(v -> {
            int pos = (int) v.getTag();
            if(mOnCheckBoxClickListener!=null){
                mOnCheckBoxClickListener.onCheckClick(pos);
            }
        });
    }

    public interface OnModifyClickListener{
        void modify(int pos);
    }
    public void setModifyListener(OnModifyClickListener listener){
        mOnModifyClickListener = listener;
    }
    private OnModifyClickListener mOnModifyClickListener;

    public interface OnCheckBoxClickListener{
        void onCheckClick(int pos);
    }

    private OnCheckBoxClickListener mOnCheckBoxClickListener;

    public void setOnCheckBoxClickListener(OnCheckBoxClickListener onCheckBoxClickListeter) {
        mOnCheckBoxClickListener = onCheckBoxClickListeter;
    }
}

